package edu.ptu.shortlink.project.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import edu.ptu.shortlink.project.dao.entity.LinkStatsTodayDO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;

/**
 * @BelongsProject: shortlink
 * @BelongsPackage: edu.ptu.shortlink.project.dao.mapper
 * @Author: HYJ
 * @CreateTime: 2025-05-11  17:37
 * @Description: 短链接今日访问统计持久层
 * @Version: 1.0
 */
public interface LinkStatsTodayMapper extends BaseMapper<LinkStatsTodayDO> {
    /**
     * 短链接今日访问统计
     *
     * @param linkStatsTodayDO 短链接今日访问统计实体类
     */
    @Insert("INSERT INTO t_link_stats_today (gid, full_short_url, date, today_pv, today_uv, today_uip, create_time, update_time, del_flag) " +
            "VALUES (#{linkStatsTodayDO.gid}, #{linkStatsTodayDO.fullShortUrl}, #{linkStatsTodayDO.date}, #{linkStatsTodayDO.todayPv}, #{linkStatsTodayDO.todayUv}, #{linkStatsTodayDO.todayUip}, NOW(), NOW(), 0) " +
            "ON DUPLICATE KEY UPDATE today_pv = today_pv + #{linkStatsTodayDO.todayPv}, today_uv = today_uv + #{linkStatsTodayDO.todayUv}, today_uip = today_uip + #{linkStatsTodayDO.todayUip};")
    void shortLinkStatsToday(@Param("linkStatsTodayDO") LinkStatsTodayDO linkStatsTodayDO);
}
